package com.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shop.annotation.RequireRoles;
import com.shop.entity.MerchantCategory;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import com.shop.service.MerchantCategoryService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * (MerchantCategory)表控制层
 *
 * @author makejava
 * @since 2020-11-21 09:47:58
 */
@Validated
@RestController
@RequestMapping("category")
@AllArgsConstructor
public class MerchantCategoryController {
    /**
     * 服务对象
     */
    private final MerchantCategoryService merchantCategoryService;

    @GetMapping("getByMerchantId")
    public Rsp getByMerchantId(@NotNull int id){
        System.out.println("id:"+id);
        return merchantCategoryService.getByMerchantId(id);
    }

    /**
     * 查询商品类别列表
     * 无分页
     */
    @RequireRoles(roles = {"merchant"})
    @PostMapping("getCategoryList")
    public Rsp getCategoryList(@RequestHeader Integer merchantId){
        return Rsp.success(merchantCategoryService.getCategoryList(merchantId));
    }

    /**
     * 修改类别名
     */
    @PostMapping("updateCategoryName")
    public Rsp updateCategoryName(@RequestBody MerchantCategory merchantCategory,
                                  @RequestHeader("userId")Integer userId){
        return Rsp.success(merchantCategoryService.updateCategoryName(merchantCategory,userId));
    }
    /**
     * 新增类别
     */
    @PostMapping("insertCategory")
    public Rsp insertCategory(@RequestBody MerchantCategory merchantCategory,
                              @RequestHeader("merchantId")Integer merchantId){
        return Rsp.success(merchantCategoryService.insertCategory(merchantCategory,merchantId));
    }

    /**
     * 删除类别
     *
     */
    @PostMapping("delCategory")
    public Rsp delCategory(@RequestBody  MerchantCategory merchantCategory){
        return Rsp.success(merchantCategoryService.delCategory(merchantCategory.getId()));
    }
    /**
     * @author Clh
     * @description 分页 模糊查询
     * @date  2020/11/26 9:36
     * @param pageParam
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("searchSomeByPage")
    public Rsp searchSomeByPage(@RequestBody PageParam<MerchantCategory> pageParam,
                                @RequestHeader("merchantId")Integer merchantId){

        return Rsp.success(merchantCategoryService.searchSomeByPage(pageParam,merchantId));
    }
    /**
     * @author Clh
     * @description 新增类别
     * @date  2020/11/25 19:41
     * @param merchantCategory 类别实体类
     * @param merchantId 商户id
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("insertSelective")
    public Rsp insertSelective(@RequestBody MerchantCategory merchantCategory,
                               @RequestHeader Integer merchantId,
                               @RequestHeader Integer userId){
       return merchantCategoryService.insertSelective(merchantCategory,merchantId,userId);
    }


}


